/* 
 *   Date       Developer         Description
 *   2017-09-07 周成功      新建
 * 
 *
 *   Classname:  com.titan.demo.commons.DaoImpl.PlayLogDaoImpl
 * 
 *   The source code contained in this listing is proprietary to
 *   Baby Footmarks studio.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2017 Baby Footmarks studio.
 */
package com.titan.demo.commons.DaoImpl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.stereotype.Component;

import com.titan.core.base.BaseDao;
import com.titan.core.utils.db.JdbcUtils;
import com.titan.core.utils.object.Args;
import com.titan.demo.commons.RowMapper.PlayLogRowMapper;
import com.titan.demo.commons.domain.PlayLogDomain;
import com.titan.demo.commons.Where.PlayLogWhere;
import com.titan.demo.commons.dao.IPlayLogDao;


/**
 * 根据数据库表play_log创建的DaoImpl类
 *
 * @author 周成功
 *
 */
@Component
public class PlayLogDaoImpl extends BaseDao implements IPlayLogDao {
    private static final long serialVersionUID = 1L;

    @Override
    public PlayLogDomain findByKey(String token, String id) throws Exception {
        assertNotNull("token", token);
        assertNotNull("id", id);
        
        String sql = "select * from play_log  where id=?";
        PlayLogDomain domain = JdbcUtils.queryForObject(sql, new PlayLogRowMapper(), id);
        return domain;
    }
    
    @Override
    public PlayLogDomain findByKey(String token, PlayLogDomain domain) throws Exception {
        return findByKey(token, domain.getId());
    }
    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, String where) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = buildSelect(fields);
        if( (where!=null)&&(!"".equals(where)) ) {
            sql.append(" where ").append(where);
        }
        return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper());
    }
    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, String where, int pageIndex, int pageSize) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = buildSelect(fields);
        if( (where!=null)&&(!"".equals(where)) ) {
            sql.append(" where ").append(where);
        }
        sql.append(" limit ").append((pageIndex-1)*pageSize).append(",").append(pageSize);
        return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper());
    }

    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, PlayLogWhere where) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = buildSelect(fields);
        if(where==null) {
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper());
        } else {
            sql.append(where.toSql(true));
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), where.toObjects());
        }
    }
    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, PlayLogWhere where, int pageIndex, int pageSize) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = buildSelect(fields);
        if(where==null) {
            sql.append(" limit ").append((pageIndex-1)*pageSize).append(",").append(pageSize);
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper());
        } else {
            sql.append(where.toSql(true));
            sql.append(" limit ").append((pageIndex-1)*pageSize).append(",").append(pageSize);
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), where.toObjects());
        }
    }
    
    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, String[][] where) throws Exception {
        assertNotNull("token", token);
        
        List<Object> args = new ArrayList<Object>();
        try {
            StringBuilder sql = buildSelect(fields);
            int len = where.length;
            for(int i=0; i<len; i++) {
                if(i==0) {
                    sql.append(" where ");
                } else {
                    sql.append(" and ");
                }
                sql.append(where[i][0]);
                args.add(where[i][1]);
            }
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
        }
    }
    
    public List<PlayLogDomain> findByWhere(String token, String[] fields, String[][] where, int pageIndex, int pageSize) throws Exception {
        assertNotNull("token", token);
        
        List<Object> args = new ArrayList<Object>();
        try {
            StringBuilder sql = buildSelect(fields);
            int len = where.length;
            for(int i=0; i<len; i++) {
                if(i==0) {
                    sql.append(" where ");
                } else {
                    sql.append(" and ");
                }
                sql.append(where[i][0]);
                args.add(where[i][1]);
            }
            sql.append(" limit ").append((pageIndex-1)*pageSize).append(",").append(pageSize);
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
        }
    }

    private static StringBuilder buildSelect(String[] fields) {
        StringBuilder sql = new StringBuilder(128);
        sql.append("select ");
        if( fields==null || fields.length==0 ) {
            sql.append("*");
        } else {
            int len = fields.length;
            for (int i = 0; i < len; i++) {
                if(i>0) {
                    sql.append(",");
                }
                sql.append(fields[i]);
            }
        }
        sql.append(" from play_log");
        return sql;
    }
    private static StringBuilder buildSelect(List<Object> args, PlayLogDomain domain, String[] fields) {
        StringBuilder sql = buildSelect(fields);
        if(domain==null) {
            return sql;
        } else {
            buildWhere(sql, args, domain);
        }
        return sql;
    }
    private static void buildWhere(StringBuilder sql, List<Object> args, PlayLogDomain domain) {
        if(domain==null) {
            return;
        }
        int countWhere = 0;
        countWhere = countWhere + where("id", domain.getId(), sql, args, countWhere);
        countWhere = countWhere + where("group1", domain.getGroup1(), sql, args, countWhere);
        countWhere = countWhere + where("group2", domain.getGroup2(), sql, args, countWhere);
        countWhere = countWhere + where("group3", domain.getGroup3(), sql, args, countWhere);
        countWhere = countWhere + where("group4", domain.getGroup4(), sql, args, countWhere);
        countWhere = countWhere + where("group5", domain.getGroup5(), sql, args, countWhere);
        countWhere = countWhere + where("server_id", domain.getServer_id(), sql, args, countWhere);
        countWhere = countWhere + where("server_ip", domain.getServer_ip(), sql, args, countWhere);
        countWhere = countWhere + where("server_port", domain.getServer_port(), sql, args, countWhere);
        countWhere = countWhere + where("user_id", domain.getUser_id(), sql, args, countWhere);
        countWhere = countWhere + where("user_ip", domain.getUser_ip(), sql, args, countWhere);
        countWhere = countWhere + where("user_header", domain.getUser_header(), sql, args, countWhere);
        countWhere = countWhere + where("user_uri", domain.getUser_uri(), sql, args, countWhere);
        countWhere = countWhere + where("message1", domain.getMessage1(), sql, args, countWhere);
        countWhere = countWhere + where("message2", domain.getMessage2(), sql, args, countWhere);
        countWhere = countWhere + where("message3", domain.getMessage3(), sql, args, countWhere);
        countWhere = countWhere + where("message4", domain.getMessage4(), sql, args, countWhere);
        countWhere = countWhere + where("message5", domain.getMessage5(), sql, args, countWhere);
        countWhere = countWhere + where("message6", domain.getMessage6(), sql, args, countWhere);
        countWhere = countWhere + where("message7", domain.getMessage7(), sql, args, countWhere);
        countWhere = countWhere + where("message8", domain.getMessage8(), sql, args, countWhere);
        countWhere = countWhere + where("message9", domain.getMessage9(), sql, args, countWhere);
        countWhere = countWhere + where("attribute1", domain.getAttribute1(), sql, args, countWhere);
        countWhere = countWhere + where("attribute2", domain.getAttribute2(), sql, args, countWhere);
        countWhere = countWhere + where("attribute3", domain.getAttribute3(), sql, args, countWhere);
        countWhere = countWhere + where("attribute4", domain.getAttribute4(), sql, args, countWhere);
        countWhere = countWhere + where("attribute5", domain.getAttribute5(), sql, args, countWhere);
        countWhere = countWhere + where("create_name", domain.getCreate_name(), sql, args, countWhere);
        countWhere = countWhere + where("create_dt", domain.getCreate_dt(), sql, args, countWhere);
        countWhere = countWhere + where("update_name", domain.getUpdate_name(), sql, args, countWhere);
        countWhere = countWhere + where("update_dt", domain.getUpdate_dt(), sql, args, countWhere);
        countWhere = countWhere + where("delete_flag", domain.getDelete_flag(), sql, args, countWhere);
        countWhere = countWhere + where("delete_name", domain.getDelete_name(), sql, args, countWhere);
        countWhere = countWhere + where("delete_dt", domain.getDelete_dt(), sql, args, countWhere);
    }    
        

    public List<PlayLogDomain> findByWhere(String token, String[] fields, PlayLogDomain domain) throws Exception {
        assertNotNull("token", token);
        List<Object> args = new ArrayList<Object>();
        try {
            StringBuilder sql = buildSelect(args, domain, fields);        
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
        }
    }

    @Override
    public List<PlayLogDomain> findByWhere(String token, String[] fields, PlayLogDomain domain, int pageIndex, int pageSize) throws Exception {
        assertNotNull("token", token);
        List<Object> args = new ArrayList<Object>();
        try {
            StringBuilder sql = buildSelect(args, domain, fields);
            sql.append(" limit ").append((pageIndex-1)*pageSize).append(",").append(pageSize);
            return JdbcUtils.queryForList(sql.toString(), new PlayLogRowMapper(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
        }
    }
    
    
    public List<PlayLogDomain> findByWhere(String token, String where) throws Exception {
        return findByWhere(token, null, where);
    }
    public List<PlayLogDomain> findByWhere(String token, String where, int pageIndex, int pageSize) throws Exception {
        return findByWhere(token, null, where, pageIndex, pageSize);
    }
    public List<PlayLogDomain> findByWhere(String token, String[][] where) throws Exception {
        return findByWhere(token, null, where);
    }
    public List<PlayLogDomain> findByWhere(String token, String[][] where, int pageIndex, int pageSize) throws Exception {
        return findByWhere(token, null, where, pageIndex, pageSize);
    }
    public List<PlayLogDomain> findByWhere(String token, PlayLogWhere where) throws Exception {
        return findByWhere(token, null, where);
    }
    public List<PlayLogDomain> findByWhere(String token, PlayLogWhere where, int pageIndex, int pageSize) throws Exception {
        return findByWhere(token, null, where, pageIndex, pageSize);
    }
    public List<PlayLogDomain> findByWhere(String token, PlayLogDomain domain) throws Exception {
        return findByWhere(token, null, domain);
    }
    public List<PlayLogDomain> findByWhere(String token, PlayLogDomain domain, int pageIndex, int pageSize) throws Exception {
        return findByWhere(token, null, domain, pageIndex, pageSize);
    }
    
    
    public int findCountByWhere(String token, String where) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = new StringBuilder(128);
        sql.append("select count(1) from play_log ");
        if( (where!=null)&&(!"".equals(where)) ) {
            sql.append(where);
        }
        return JdbcUtils.queryForInt(sql.toString());
    }
    public int findCountByWhere(String token, PlayLogWhere where) throws Exception {
        assertNotNull("token", token);
        StringBuilder sql = new StringBuilder(128);
        sql.append("select count(1) from play_log ");
        if(where==null) {
            return JdbcUtils.queryForInt(sql.toString());
        } else {
            sql.append(where.toSql(false));
            return JdbcUtils.queryForInt(sql.toString(), where.toObjects());
        }
    }    
    public int findCountByWhere(String token, String[][] where) throws Exception {
        assertNotNull("token", token);
        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder(128);
        sql.append("select count(1) from play_log ");
        int len = where.length;
        for(int i=0; i<len; i++) {
            if(i==0) {
                sql.append(" where ");
            } else {
                sql.append(" and ");
            }
            sql.append(where[i][0]);
            args.add(where[i][1]);
        }
        try {
            return JdbcUtils.queryForInt(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }
    }


    public int findCountByWhere(String token, PlayLogDomain domain) throws Exception {
        assertNotNull("token", token);
        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder(128);
        sql.append("select count(1) from play_log");
        if(domain!=null) {
            int countWhere = 0;
            countWhere = countWhere + where("id", domain.getId(), sql, args, countWhere);
            countWhere = countWhere + where("group1", domain.getGroup1(), sql, args, countWhere);
            countWhere = countWhere + where("group2", domain.getGroup2(), sql, args, countWhere);
            countWhere = countWhere + where("group3", domain.getGroup3(), sql, args, countWhere);
            countWhere = countWhere + where("group4", domain.getGroup4(), sql, args, countWhere);
            countWhere = countWhere + where("group5", domain.getGroup5(), sql, args, countWhere);
            countWhere = countWhere + where("server_id", domain.getServer_id(), sql, args, countWhere);
            countWhere = countWhere + where("server_ip", domain.getServer_ip(), sql, args, countWhere);
            countWhere = countWhere + where("server_port", domain.getServer_port(), sql, args, countWhere);
            countWhere = countWhere + where("user_id", domain.getUser_id(), sql, args, countWhere);
            countWhere = countWhere + where("user_ip", domain.getUser_ip(), sql, args, countWhere);
            countWhere = countWhere + where("user_header", domain.getUser_header(), sql, args, countWhere);
            countWhere = countWhere + where("user_uri", domain.getUser_uri(), sql, args, countWhere);
            countWhere = countWhere + where("message1", domain.getMessage1(), sql, args, countWhere);
            countWhere = countWhere + where("message2", domain.getMessage2(), sql, args, countWhere);
            countWhere = countWhere + where("message3", domain.getMessage3(), sql, args, countWhere);
            countWhere = countWhere + where("message4", domain.getMessage4(), sql, args, countWhere);
            countWhere = countWhere + where("message5", domain.getMessage5(), sql, args, countWhere);
            countWhere = countWhere + where("message6", domain.getMessage6(), sql, args, countWhere);
            countWhere = countWhere + where("message7", domain.getMessage7(), sql, args, countWhere);
            countWhere = countWhere + where("message8", domain.getMessage8(), sql, args, countWhere);
            countWhere = countWhere + where("message9", domain.getMessage9(), sql, args, countWhere);
            countWhere = countWhere + where("attribute1", domain.getAttribute1(), sql, args, countWhere);
            countWhere = countWhere + where("attribute2", domain.getAttribute2(), sql, args, countWhere);
            countWhere = countWhere + where("attribute3", domain.getAttribute3(), sql, args, countWhere);
            countWhere = countWhere + where("attribute4", domain.getAttribute4(), sql, args, countWhere);
            countWhere = countWhere + where("attribute5", domain.getAttribute5(), sql, args, countWhere);
            countWhere = countWhere + where("create_name", domain.getCreate_name(), sql, args, countWhere);
            countWhere = countWhere + where("create_dt", domain.getCreate_dt(), sql, args, countWhere);
            countWhere = countWhere + where("update_name", domain.getUpdate_name(), sql, args, countWhere);
            countWhere = countWhere + where("update_dt", domain.getUpdate_dt(), sql, args, countWhere);
            countWhere = countWhere + where("delete_flag", domain.getDelete_flag(), sql, args, countWhere);
            countWhere = countWhere + where("delete_name", domain.getDelete_name(), sql, args, countWhere);
            countWhere = countWhere + where("delete_dt", domain.getDelete_dt(), sql, args, countWhere);
        }        
        try {
            return JdbcUtils.queryForInt(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }
    }
    

    public int insert(String token, PlayLogDomain domain) throws Exception {
        assertNotNull("token", token);
        assertNotNull("domain", domain);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        String sql = "insert into play_log(id,group1,group2,group3,group4,group5,server_id,server_ip,server_port,user_id,user_ip,user_header,user_uri,message1,message2,message3,message4,message5,message6,message7,message8,message9,attribute1,attribute2,attribute3,attribute4,attribute5,create_name,create_dt,update_name,update_dt,delete_flag,delete_name,delete_dt) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,sysdate(),?,sysdate(),?,?,?)";
        return JdbcUtils.update(sql, domain.getId(), domain.getGroup1(), domain.getGroup2(), domain.getGroup3(), domain.getGroup4(), domain.getGroup5(), domain.getServer_id(), domain.getServer_ip(), domain.getServer_port(), domain.getUser_id(), domain.getUser_ip(), domain.getUser_header(), domain.getUser_uri(), domain.getMessage1(), domain.getMessage2(), domain.getMessage3(), domain.getMessage4(), domain.getMessage5(), domain.getMessage6(), domain.getMessage7(), domain.getMessage8(), domain.getMessage9(), domain.getAttribute1(), domain.getAttribute2(), domain.getAttribute3(), domain.getAttribute4(), domain.getAttribute5(), op, op, domain.getDelete_flag(), domain.getDelete_name(), domain.getDelete_dt());
    }


    public int updateByKey(String token, String id, Args args) throws Exception {
        assertNotNull("token", token);
        assertNotNull("args", args);
        assertNotNull("id", id);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        StringBuilder sql = new StringBuilder(256);
        sql.append("update play_log");
        String[] keys = args.getKeys();
        List<Object> values = new ArrayList<Object>();
        for(int i=0; i<keys.length; i++) {
            if( i==0 ) {
                sql.append(" set ").append(keys[i]).append("=?");
            } else {
                sql.append(" , ").append(keys[i]).append("=?");
            }
            values.add(args.getValue(keys[i]));
        }
        sql.append(" , update_dt=sysdate()");
        sql.append(" , update_name=?");
        sql.append(" where id=?");
        values.add(op);
        values.add(id);
        
        return JdbcUtils.update(sql.toString(), values.toArray(new Object[values.size()]));
    }


    public int updateByKey(String token, String id, String fieldName, Object fieldValue) throws Exception {
        assertNotNull("token", token);
        assertNotNull("fieldName", fieldName);
        assertNotNull("fieldValue", fieldValue);
        assertNotNull("id", id);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        String sql = "update play_log set "+fieldName+"=?,update_dt=sysdate(),update_name=? where id=?";
        return JdbcUtils.update(sql, fieldValue, op, id);
    }

    public int updateByKey(String token, PlayLogDomain domain, String[] updateFields, String[] useSysdate) throws Exception {
        assertNotNull("token", token);
        assertNotNull("domain", domain);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        Set<String> set = new HashSet<String>();
        set.add("create_dt");
        set.add("update_dt");
        set.add("delete_dt");
        if(useSysdate!=null) {
            for(int i=0; i<useSysdate.length; i++) {
                set.add(useSysdate[i].toLowerCase());
            }
        }        
        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder(128);
        sql.append("update play_log set ");
        if(updateFields==null) {
            update(op, "id", domain.getId(), sql, args, set);
            update(op, "group1", domain.getGroup1(), sql.append(", "), args, set);
            update(op, "group2", domain.getGroup2(), sql.append(", "), args, set);
            update(op, "group3", domain.getGroup3(), sql.append(", "), args, set);
            update(op, "group4", domain.getGroup4(), sql.append(", "), args, set);
            update(op, "group5", domain.getGroup5(), sql.append(", "), args, set);
            update(op, "server_id", domain.getServer_id(), sql.append(", "), args, set);
            update(op, "server_ip", domain.getServer_ip(), sql.append(", "), args, set);
            update(op, "server_port", domain.getServer_port(), sql.append(", "), args, set);
            update(op, "user_id", domain.getUser_id(), sql.append(", "), args, set);
            update(op, "user_ip", domain.getUser_ip(), sql.append(", "), args, set);
            update(op, "user_header", domain.getUser_header(), sql.append(", "), args, set);
            update(op, "user_uri", domain.getUser_uri(), sql.append(", "), args, set);
            update(op, "message1", domain.getMessage1(), sql.append(", "), args, set);
            update(op, "message2", domain.getMessage2(), sql.append(", "), args, set);
            update(op, "message3", domain.getMessage3(), sql.append(", "), args, set);
            update(op, "message4", domain.getMessage4(), sql.append(", "), args, set);
            update(op, "message5", domain.getMessage5(), sql.append(", "), args, set);
            update(op, "message6", domain.getMessage6(), sql.append(", "), args, set);
            update(op, "message7", domain.getMessage7(), sql.append(", "), args, set);
            update(op, "message8", domain.getMessage8(), sql.append(", "), args, set);
            update(op, "message9", domain.getMessage9(), sql.append(", "), args, set);
            update(op, "attribute1", domain.getAttribute1(), sql.append(", "), args, set);
            update(op, "attribute2", domain.getAttribute2(), sql.append(", "), args, set);
            update(op, "attribute3", domain.getAttribute3(), sql.append(", "), args, set);
            update(op, "attribute4", domain.getAttribute4(), sql.append(", "), args, set);
            update(op, "attribute5", domain.getAttribute5(), sql.append(", "), args, set);
            update(op, "create_name", domain.getCreate_name(), sql.append(", "), args, set);
            update(op, "create_dt", domain.getCreate_dt(), sql.append(", "), args, set);
            update(op, "update_name", domain.getUpdate_name(), sql.append(", "), args, set);
            update(op, "update_dt", domain.getUpdate_dt(), sql.append(", "), args, set);
            update(op, "delete_flag", domain.getDelete_flag(), sql.append(", "), args, set);
            update(op, "delete_name", domain.getDelete_name(), sql.append(", "), args, set);
            update(op, "delete_dt", domain.getDelete_dt(), sql.append(", "), args, set);
        } else {
            int len = updateFields.length;
            for(int i=0; i<len; i++) {
                String field = updateFields[i].toLowerCase();
                if(i>0) {
                    sql.append(", ");
                }
                update(op, field, domain.getValue(field).getValue(), sql, args, set);
            }
        }
        args.add(domain.getValue("id").getValue());
        sql.append(" where id=?");
        try {
            return JdbcUtils.update(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }
    }


    @Override
    public int updateByKeySetAll(String token, PlayLogDomain domain) throws Exception {
        assertNotNull("token", token);
        assertNotNull("domain", domain);

        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder(128);
        sql.append("update play_log set ");
        sql.append("id").append("=?"); args.add(domain.getId());
        sql.append(",group1").append("=?"); args.add(domain.getGroup1());
        sql.append(",group2").append("=?"); args.add(domain.getGroup2());
        sql.append(",group3").append("=?"); args.add(domain.getGroup3());
        sql.append(",group4").append("=?"); args.add(domain.getGroup4());
        sql.append(",group5").append("=?"); args.add(domain.getGroup5());
        sql.append(",server_id").append("=?"); args.add(domain.getServer_id());
        sql.append(",server_ip").append("=?"); args.add(domain.getServer_ip());
        sql.append(",server_port").append("=?"); args.add(domain.getServer_port());
        sql.append(",user_id").append("=?"); args.add(domain.getUser_id());
        sql.append(",user_ip").append("=?"); args.add(domain.getUser_ip());
        sql.append(",user_header").append("=?"); args.add(domain.getUser_header());
        sql.append(",user_uri").append("=?"); args.add(domain.getUser_uri());
        sql.append(",message1").append("=?"); args.add(domain.getMessage1());
        sql.append(",message2").append("=?"); args.add(domain.getMessage2());
        sql.append(",message3").append("=?"); args.add(domain.getMessage3());
        sql.append(",message4").append("=?"); args.add(domain.getMessage4());
        sql.append(",message5").append("=?"); args.add(domain.getMessage5());
        sql.append(",message6").append("=?"); args.add(domain.getMessage6());
        sql.append(",message7").append("=?"); args.add(domain.getMessage7());
        sql.append(",message8").append("=?"); args.add(domain.getMessage8());
        sql.append(",message9").append("=?"); args.add(domain.getMessage9());
        sql.append(",attribute1").append("=?"); args.add(domain.getAttribute1());
        sql.append(",attribute2").append("=?"); args.add(domain.getAttribute2());
        sql.append(",attribute3").append("=?"); args.add(domain.getAttribute3());
        sql.append(",attribute4").append("=?"); args.add(domain.getAttribute4());
        sql.append(",attribute5").append("=?"); args.add(domain.getAttribute5());
        sql.append(",create_name").append("=?"); args.add(domain.getCreate_name());
        sql.append(",create_dt").append("=?"); args.add(domain.getCreate_dt());
        sql.append(",update_name").append("=?"); args.add(domain.getUpdate_name());
        sql.append(",update_dt").append("=?"); args.add(domain.getUpdate_dt());
        sql.append(",delete_flag").append("=?"); args.add(domain.getDelete_flag());
        sql.append(",delete_name").append("=?"); args.add(domain.getDelete_name());
        sql.append(",delete_dt").append("=?"); args.add(domain.getDelete_dt());
        args.add(domain.getValue("id").getValue());
        sql.append(" where id=?");
        try {
            return JdbcUtils.update(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }
    }
    
    
    public int updateByKeySetNull(String token, String id, String...fields) throws Exception {
        assertNotNull("token", token);
        assertNotNull("fields", fields);
        assertNotNull("id", id);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        StringBuilder sql = new StringBuilder(256);
        sql.append("update play_log");
        for(int i=0; i<fields.length; i++) {
            if( i==0 ) {
                sql.append(" set ").append(fields[i]).append("=null");
            } else {
                sql.append(" , ").append(fields[i]).append("=null");
            }
        }
        sql.append(" , update_dt=sysdate()");
        sql.append(" , update_name=?");
        sql.append(" where id=?");
        
        return JdbcUtils.update(sql.toString(), op, id);
    }
    
    
    public int deleteByKey(String token, String id) throws Exception {
        assertNotNull("token", token);
        assertNotNull("id", id);
        String sql = "delete from play_log  where id=?";
        return JdbcUtils.update(sql.toString(), id);
    }


    @Override
    public int deleteByKey(String token, PlayLogDomain domain) throws Exception {
        assertNotNull("token", token);
        assertNotNull("domain", domain);
        return deleteByKey(token, domain.getId());
    }
    
    
    @Override
    public int delete(String token, String where) throws Exception {
        assertNotNull("token", token);
        assertNotNull("where", where);
        StringBuilder sql = new StringBuilder("delete from play_log");
        if( (where!=null)&&(!"".equals(where)) ) {
            sql.append(" where ").append(where);
        }        
        return JdbcUtils.update(sql.toString());
    }
    
    
    @Override
    public int delete(String token, String[][] where) throws Exception {
        assertNotNull("token", token);
        assertNotNull("where", where);
        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder("delete from play_log");
        int len = where.length;
        for(int i=0; i<len; i++) {
            if(i==0) {
                sql.append(" where ");
            } else {
                sql.append(" and ");
            }
            sql.append(where[i][0]);
            args.add(where[i][1]);
        }
        try {
            return JdbcUtils.update(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }        
    }
    
    
    @Override
    public int delete(String token, PlayLogWhere where) throws Exception {
        assertNotNull("token", token);
        assertNotNull("where", where);
        StringBuilder sql = new StringBuilder("delete from play_log");
        sql.append(where.toSql(false));
        return JdbcUtils.update(sql.toString(), where.toObjects());
    }
    
    
    @Override
    public int delete(String token, PlayLogDomain where) throws Exception {
        assertNotNull("token", token);
        assertNotNull("where", where);
        List<Object> args = new ArrayList<Object>();
        StringBuilder sql = new StringBuilder("delete from play_log");
        buildWhere(sql, args, where);
        try {
            return JdbcUtils.update(sql.toString(), args.toArray(new Object[args.size()]));
        } finally {
            args.clear();
            args = null;
            sql = null;
        }        
    }
        

    public int closeByKey(String token, String id) throws Exception {
        assertNotNull("token", token);
        assertNotNull("id", id);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        String sql = "update play_log set delete_flag=1,delete_dt=sysdate(),delete_name=? where id=?";
        return JdbcUtils.update(sql, op, id);
    }


    public int openByKey(String token, String id) throws Exception {
        assertNotNull("token", token);
        assertNotNull("id", id);
        //String op = userinfo.getOpname();
        String op = "sys";
        
        String sql = "update play_log set delete_flag=0,delete_dt=sysdate(),delete_name=? where id=?";
        return JdbcUtils.update(sql, op, id);
    }   
}

